Import monkeylua
Import mojo

Private

' From mojo/app.monkey
Class MojoFuncAppTitle Extends MonkeyFunction
	Method Func:Int(state:LuaState)
		state.PushString("")'AppTitle())
		Return 1
	End
End

Class MojoFuncLoadState Extends MonkeyFunction
	Method Func:Int(state:LuaState)
		state.PushString(LoadState())
		Return 1
	End
End

Class MojoFuncSaveState Extends MonkeyFunction
	Method Func:Int(state:LuaState)
		Local rv:String = SaveState(state.ToString(1))
		state.PushString(rv)
		Return 1
	End
End

Class MojoFuncLoadString Extends MonkeyFunction
	Method Func:Int(state:LuaState)
		Local path:String = state.ToString(1)
		state.PushString(LoadString(path))
		Return 1
	End
End

Class MojoFuncSetUpdateRate Extends MonkeyFunction
	Method Func:Int(state:LuaState)
		Local ur:Int = state.ToInteger(1)
		state.PushInteger(SetUpdateRate(ur))
		Return 1
	End
End

Class MojoFuncUpdateRate Extends MonkeyFunction
	Method Func:Int(state:LuaState)
		state.PushInteger(UpdateRate())
		Return 1
	End
End

Class MojoFuncMillisecs Extends MonkeyFunction
	Method Func:Int(state:LuaState)
		state.PushInteger(Millisecs())
		Return 1
	End
End

' From mojo/audio.monkey
Class MojoFuncSetAudioDevice Extends MonkeyFunction
	Method Func:Int(state:LuaState)
		Local dev:AudioDevice = AudioDevice(state.ToMonkeyObject(1))
		state.PushInteger(SetAudioDevice(dev))
		Return 1
	End
End

Class MojoFuncLoadSound Extends MonkeyFunction
	Method Func:Int(state:LuaState)
		Local path:String = state.ToString(1)
		Local sound:Sound = LoadSound(path)
		If sound Then
			state.PushMonkeyObject(sound)
		Else
			state.PushNil()
		End
		Return 1
	End
End

Class MojoFuncPlaySound Extends MonkeyFunction
	Method Func:Int(state:LuaState)
		Local sound:Sound = Sound(state.ToMonkeyObject(1))
		Local channel:Int = state.OptInteger(2,0)
		Local flags:Int = state.OptInteger(3,0)
		state.PushInteger(PlaySound(sound, channel, flags))
		Return 1
	End
End

Class MojoFuncStopChannel Extends MonkeyFunction
	Method Func:Int(state:LuaState)
		Local channel:Int = state.ToInteger(1)
		state.PushInteger(StopChannel(channel))
		Return 1
	End
End

Class MojoFuncPauseChannel Extends MonkeyFunction
	Method Func:Int(state:LuaState)
		Local channel:Int = state.ToInteger(1)
		state.PushInteger(PauseChannel(channel))
		Return 1
	End
End

Class MojoFuncResumeChannel Extends MonkeyFunction
	Method Func:Int(state:LuaState)
		Local channel:Int = state.ToInteger(1)
		state.PushInteger(ResumeChannel(channel))
		Return 1
	End
End

Class MojoFuncChannelState Extends MonkeyFunction
	Method Func:Int(state:LuaState)
		Local channel:Int = state.ToInteger(1)
		state.PushInteger(ChannelState(channel))
		Return 1
	End
End

Class MojoFuncSetChannelVolume Extends MonkeyFunction
	Method Func:Int(state:LuaState)
		Local channel:Int = state.ToInteger(1)
		Local volume:Float = state.ToNumber(2)
		state.PushInteger(SetChannelVolume(channel, volume))
		Return 1
	End
End

Class MojoFuncSetChannelPan Extends MonkeyFunction
	Method Func:Int(state:LuaState)
		Local channel:Int = state.ToInteger(1)
		Local pan:Float = state.ToNumber(2)
		state.PushInteger(SetChannelPan(channel, pan))
		Return 1
	End
End

Class MojoFuncSetChannelRate Extends MonkeyFunction
	Method Func:Int(state:LuaState)
		Local channel:Int = state.ToInteger(1)
		Local rate:Float = state.ToNumber(2)
		state.PushInteger(SetChannelRate(channel, rate))
		Return 1
	End
End

Class MojoFuncPlayMusic Extends MonkeyFunction
	Method Func:Int(state:LuaState)
		Local path:String = state.ToString(1)
		Local flags:Int = state.OptInteger(2,1)
		state.PushInteger(PlayMusic(path, flags))
		Return 1
	End
End

Class MojoFuncStopMusic Extends MonkeyFunction
	Method Func:Int(state:LuaState)
		state.PushInteger(StopMusic())
		Return 1
	End
End

Class MojoFuncPauseMusic Extends MonkeyFunction
	Method Func:Int(state:LuaState)
		state.PushInteger(PauseMusic())
		Return 1
	End
End

Class MojoFuncResumeMusic Extends MonkeyFunction
	Method Func:Int(state:LuaState)
		state.PushInteger(ResumeMusic())
		Return 1
	End
End

Class MojoFuncMusicState Extends MonkeyFunction
	Method Func:Int(state:LuaState)
		state.PushInteger(MusicState())
		Return 1
	End
End

Class MojoFuncSetMusicVolume Extends MonkeyFunction
	Method Func:Int(state:LuaState)
		Local volume:Float = state.ToNumber(1)
		state.PushInteger(SetMusicVolume(volume))
		Return 1
	End
End

' From mojo/graphics.monkey
Class MojoFuncDeviceWidth Extends MonkeyFunction
	Method Func:Int(state:LuaState)
		state.PushInteger(DeviceWidth())
		Return 1
	End
End

Class MojoFuncDeviceHeight Extends MonkeyFunction
	Method Func:Int(state:LuaState)
		state.PushInteger(DeviceHeight())
		Return 1
	End
End

Class MojoFuncLoadImage Extends MonkeyFunction
	Method Func:Int(state:LuaState)
		Local path:String, frameCount:Int, frameWidth:Int, frameHeight:Int, flags:Int
		Local img:Image
		' path$,frameCount=1,flags=Image.DefaultFlags (1 mandatory, 2 optional)
		If state.GetTop() <= 3 Then
			path = state.ToString(1)
			frameCount = state.OptInteger(2, 1)
			flags = state.OptInteger(3, Image.DefaultFlags)
			img = LoadImage(path, frameCount, flags)
		' path$,frameWidth,frameHeight,frameCount,flags=Image.DefaultFlags (4 mandatory, 1 optional)
		Else
			path = state.ToString(1)
			frameWidth = state.ToInteger(2)
			frameHeight = state.ToInteger(3)
			frameCount = state.ToInteger(4)
			flags = state.OptInteger(5, Image.DefaultFlags)
			img = LoadImage(path, frameWidth, frameHeight, frameCount, flags)
		End
		If img Then
			state.PushMonkeyObject(img)
		Else
			state.PushNil()
		End
		Return 1
	End
End

Class MojoFuncSetColor Extends MonkeyFunction
	Method Func:Int(state:LuaState)
		Local r:Float = state.ToNumber(1)
		Local g:Float = state.ToNumber(2)
		Local b:Float = state.ToNumber(3)
		state.PushInteger(SetColor(r, g, b))
		Return 1
	End
End

Class MojoFuncGetColor Extends MonkeyFunction
	Method Func:Int(state:LuaState)
		Local rv:Float[] = GetColor()
		state.PushNumber(rv[0])
		state.PushNumber(rv[1])
		state.PushNumber(rv[2])
		Return 3
	End
End

Class MojoFuncSetAlpha Extends MonkeyFunction
	Method Func:Int(state:LuaState)
		Local alpha:Float = state.ToNumber(1)
		state.PushInteger(SetAlpha(alpha))
		Return 1
	End
End

Class MojoFuncGetAlpha Extends MonkeyFunction
	Method Func:Int(state:LuaState)
		state.PushNumber(GetAlpha())
		Return 1
	End
End

Class MojoFuncSetBlend Extends MonkeyFunction
	Method Func:Int(state:LuaState)
		Local blend:Int = state.ToInteger(1)
		state.PushInteger(SetBlend(blend))
		Return 1
	End
End

Class MojoFuncGetBlend Extends MonkeyFunction
	Method Func:Int(state:LuaState)
		state.PushInteger(GetBlend())
		Return 1
	End
End

Class MojoFuncSetScissor Extends MonkeyFunction
	Method Func:Int(state:LuaState)
		Local x:Float = state.ToNumber(1)
		Local y:Float = state.ToNumber(2)
		Local width:Float = state.ToNumber(3)
		Local height:Float = state.ToNumber(4)
		state.PushInteger(SetScissor(x, y, width, height))
		Return 1
	End
End

Class MojoFuncGetScissor Extends MonkeyFunction
	Method Func:Int(state:LuaState)
		Local sc:Float[] = GetScissor()
		state.PushNumber(sc[0])
		state.PushNumber(sc[1])
		state.PushNumber(sc[2])
		state.PushNumber(sc[3])
		Return 4
	End
End

Class MojoFuncSetMatrix Extends MonkeyFunction
	Method Func:Int(state:LuaState)
		' TODO: handle a table input
		Local ix:Float = state.ToNumber(1)
		Local iy:Float = state.ToNumber(2)
		Local jx:Float = state.ToNumber(3)
		Local jy:Float = state.ToNumber(4)
		Local tx:Float = state.ToNumber(5)
		Local ty:Float = state.ToNumber(6)
		state.PushInteger(SetMatrix(ix, iy, jx, jy, tx, ty))
		Return 1
	End
End

Class MojoFuncGetMatrix Extends MonkeyFunction
	Method Func:Int(state:LuaState)
		Local mat:Float[] = GetMatrix()
		For Local i:Int = 0 Until mat.Length
			state.PushNumber(mat[i])
		Next
		Return mat.Length
	End
End

Class MojoFuncPushMatrix Extends MonkeyFunction
	Method Func:Int(state:LuaState)
		state.PushInteger(PushMatrix())
		Return 1
	End
End

Class MojoFuncPopMatrix Extends MonkeyFunction
	Method Func:Int(state:LuaState)
		state.PushInteger(PopMatrix())
		Return 1
	End
End

Class MojoFuncTransform Extends MonkeyFunction
	Method Func:Int(state:LuaState)
		' TODO: handle a table input
		Local ix:Float = state.ToNumber(1)
		Local iy:Float = state.ToNumber(2)
		Local jx:Float = state.ToNumber(3)
		Local jy:Float = state.ToNumber(4)
		Local tx:Float = state.ToNumber(5)
		Local ty:Float = state.ToNumber(6)
		state.PushInteger(Transform(ix, iy, jx, jy, tx, ty))
		Return 1
	End
End

Class MojoFuncTranslate Extends MonkeyFunction
	Method Func:Int(state:LuaState)
		Local x:Float = state.ToNumber(1)
		Local y:Float = state.ToNumber(2)
		state.PushInteger(Translate(x, y))
		Return 1
	End
End

Class MojoFuncScale Extends MonkeyFunction
	Method Func:Int(state:LuaState)
		Local x:Float = state.ToNumber(1)
		Local y:Float = state.ToNumber(2)
		state.PushInteger(Scale(x, y))
		Return 1
	End
End

Class MojoFuncRotate Extends MonkeyFunction
	Method Func:Int(state:LuaState)
		Local angle:Float = state.ToNumber(1)
		state.PushInteger(Rotate(angle))
		Return 1
	End
End

Class MojoFuncCls Extends MonkeyFunction
	Method Func:Int(state:LuaState)
		' warning: if the Cls defaults change in Mojo, this needs to be updated
		Local r:Float = state.OptInteger(1, 0)
		Local g:Float = state.OptInteger(2, 0)
		Local b:Float = state.OptInteger(3, 0)
		state.PushInteger(Cls(r, g, b))
		Return 1
	End
End

Class MojoFuncDrawPoint Extends MonkeyFunction
	Method Func:Int(state:LuaState)
		Local x:Float = state.ToNumber(1)
		Local y:Float = state.ToNumber(2)
		state.PushInteger(DrawPoint(x, y))
		Return 1
	End
End

Class MojoFuncDrawRect Extends MonkeyFunction
	Method Func:Int(state:LuaState)
		Local x:Float = state.ToNumber(1)
		Local y:Float = state.ToNumber(2)
		Local width:Float = state.ToNumber(3)
		Local height:Float = state.ToNumber(4)
		state.PushInteger(DrawRect(x, y, width, height))
		Return 1
	End
End

Class MojoFuncDrawLine Extends MonkeyFunction
	Method Func:Int(state:LuaState)
		Local x1:Float = state.ToNumber(1)
		Local y1:Float = state.ToNumber(2)
		Local x2:Float = state.ToNumber(3)
		Local y2:Float = state.ToNumber(4)
		state.PushInteger(DrawLine(x1, y1, x2, y2))
		Return 1
	End
End

Class MojoFuncDrawOval Extends MonkeyFunction
	Method Func:Int(state:LuaState)
		Local x:Float = state.ToNumber(1)
		Local y:Float = state.ToNumber(2)
		Local width:Float = state.ToNumber(3)
		Local height:Float = state.ToNumber(4)
		state.PushInteger(DrawOval(x, y, width, height))
		Return 1
	End
End

Class MojoFuncDrawCircle Extends MonkeyFunction
	Method Func:Int(state:LuaState)
		Local x:Float = state.ToNumber(1)
		Local y:Float = state.ToNumber(2)
		Local r:Float = state.ToNumber(3)
		state.PushInteger(DrawCircle(x, y, r))
		Return 1
	End
End

Class MojoFuncDrawEllipse Extends MonkeyFunction
	Method Func:Int(state:LuaState)
		Local x:Float = state.ToNumber(1)
		Local y:Float = state.ToNumber(2)
		Local xr:Float = state.ToNumber(3)
		Local yr:Float = state.ToNumber(4)
		state.PushInteger(DrawEllipse(x, y, xr, yr))
		Return 1
	End
End

Class MojoFuncDrawPoly Extends MonkeyFunction
	Method Func:Int(state:LuaState)
		Local verts:Float[] = New Float[state.GetTop()]
		For Local i:Int = 0 Until verts.Length
			verts[i] = state.ToNumber(i+1)
		Next
		state.PushInteger(DrawPoly(verts))
		Return 1
	End
End

Class MojoFuncDrawImage Extends MonkeyFunction
	Method Func:Int(state:LuaState)
		Local img:Image, x:Float, y:Float, frame:Int, rotation:Float, scaleX:Float, scaleY:Float
		' image:Image,x#,y#,frame=0 (3 mandatory, 1 optional)
		If state.GetTop() <= 4 Then
			img = Image(state.ToMonkeyObject(1))
			x = state.ToNumber(2)
			y = state.ToNumber(3)
			frame = state.OptInteger(4, 0)
			state.PushInteger(DrawImage(img, x, y, frame))
		' image:Image,x#,y#,rotation#,scaleX#,scaleY#,frame=0 (6 mandatory, 1 optional)
		Else
			img = Image(state.ToMonkeyObject(1))
			x = state.ToNumber(2)
			y = state.ToNumber(3)
			rotation = state.ToNumber(4)
			scaleX = state.ToNumber(5)
			scaleY = state.ToNumber(6)
			frame = state.OptInteger(7, 0)
			state.PushInteger(DrawImage(img, x, y, rotation, scaleX, scaleY, frame))
		End
		Return 1
	End
End

Class MojoFuncDrawImageRect Extends MonkeyFunction
	Method Func:Int(state:LuaState)
		Local img:Image, x:Float, y:Float, srcX:Int, srcY:Int, srcWidth:Int, srcHeight:Int, frame:Int, rotation:Float, scaleX:Float, scaleY:Float
		' image:Image,x#,y#,srcX,srcY,srcWidth,srcHeight,frame=0 (7 mandatory, 1 optional)
		If state.GetTop() <= 8 Then
			img = Image(state.ToMonkeyObject(1))
			x = state.ToNumber(2)
			y = state.ToNumber(3)
			srcX = state.ToNumber(4)
			srcY = state.ToNumber(5)
			srcWidth = state.ToNumber(6)
			srcHeight = state.ToNumber(7)
			frame = state.OptInteger(8, 0)
			state.PushInteger(DrawImageRect(img, x, y, srcX, srcY, srcWidth, srcHeight, frame))
		' image:Image,x#,y#,srcX,srcY,srcWidth,srcHeight,rotation#,scaleX#,scaleY#,frame=0 (10 mandatory, 1 optional)
		Else
			img = Image(state.ToMonkeyObject(1))
			x = state.ToNumber(2)
			y = state.ToNumber(3)
			srcX = state.ToNumber(4)
			srcY = state.ToNumber(5)
			srcWidth = state.ToNumber(6)
			srcHeight = state.ToNumber(7)
			rotation = state.ToNumber(8)
			scaleX = state.ToNumber(9)
			scaleY = state.ToNumber(10)
			frame = state.OptInteger(11, 0)
			state.PushInteger(DrawImageRect(img, x, y, srcX, srcY, srcWidth, srcHeight, rotation, scaleX, scaleY, frame))
		End
		Return 1
	End
End

Class MojoFuncSetFont Extends MonkeyFunction
	Method Func:Int(state:LuaState)
		Local font:Image = Image(state.ToMonkeyObject(1))
		Local firstChar:Int = state.OptInteger(2,32)
		state.PushInteger(SetFont(font, firstChar))
		Return 1
	End
End

Class MojoFuncGetFont Extends MonkeyFunction
	Method Func:Int(state:LuaState)
		state.PushMonkeyObject(GetFont())
		Return 1
	End
End

Class MojoFuncTextWidth Extends MonkeyFunction
	Method Func:Int(state:LuaState)
		Local text:String = state.ToString(1)
		state.PushNumber(TextWidth(text))
		Return 1
	End
End

Class MojoFuncTextHeight Extends MonkeyFunction
	Method Func:Int(state:LuaState)
		state.PushNumber(TextHeight())
		Return 1
	End
End

Class MojoFuncDrawText Extends MonkeyFunction
	Method Func:Int(state:LuaState)
		Local text:String = state.ToString(1)
		Local x:Float = state.ToNumber(2)
		Local y:Float = state.ToNumber(3)
		Local xalign:Float = state.OptNumber(4, 0)
		Local yalign:Float = state.OptNumber(5, 0)
		state.PushInteger(DrawText(text, x, y, xalign, yalign))
		Return 1
	End
End

Class MojoFuncInvTransform Extends MonkeyFunction
	Method Func:Int(state:LuaState)
		' TODO: handle a table input
		Local ix:Float = state.ToNumber(1)
		Local iy:Float = state.ToNumber(2)
		Local jx:Float = state.ToNumber(3)
		Local jy:Float = state.ToNumber(4)
		Local tx:Float = state.ToNumber(5)
		Local ty:Float = state.ToNumber(6)
		Local rv:Float[] = InvTransform([ix, iy, jx, jy, tx, ty])
		For Local i:Int = 0 Until rv.Length
			state.PushNumber(rv[i])
		Next
		Return rv.Length
	End
End

' From mojo/input.monkey
Class MojoFuncSetInputDevice Extends MonkeyFunction
	Method Func:Int(state:LuaState)
		Local dev:InputDevice = InputDevice(state.ToMonkeyObject(1))
		state.PushInteger(SetInputDevice(dev))
		Return 1
	End
End

Class MojoFuncEnableKeyboard Extends MonkeyFunction
	Method Func:Int(state:LuaState)
		state.PushInteger(EnableKeyboard())
		Return 1
	End
End

Class MojoFuncDisableKeyboard Extends MonkeyFunction
	Method Func:Int(state:LuaState)
		state.PushInteger(DisableKeyboard())
		Return 1
	End
End

Class MojoFuncKeyDown Extends MonkeyFunction
	Method Func:Int(state:LuaState)
		Local key:Int = state.ToInteger(1)
		state.PushBoolean(KeyDown(key)>0)
		Return 1
	End
End

Class MojoFuncKeyHit Extends MonkeyFunction
	Method Func:Int(state:LuaState)
		Local key:Int = state.ToInteger(1)
		state.PushBoolean(KeyHit(key)>0)
		Return 1
	End
End

Class MojoFuncGetChar Extends MonkeyFunction
	Method Func:Int(state:LuaState)
		state.PushInteger(GetChar())
		Return 1
	End
End

Class MojoFuncMouseX Extends MonkeyFunction
	Method Func:Int(state:LuaState)
		state.PushNumber(MouseX())
		Return 1
	End
End

Class MojoFuncMouseY Extends MonkeyFunction
	Method Func:Int(state:LuaState)
		state.PushNumber(MouseY())
		Return 1
	End
End

Class MojoFuncMouseDown Extends MonkeyFunction
	Method Func:Int(state:LuaState)
		state.PushBoolean(MouseDown(state.OptInteger(1, MOUSE_LEFT))>0)
		Return 1
	End
End

Class MojoFuncMouseHit Extends MonkeyFunction
	Method Func:Int(state:LuaState)
		state.PushBoolean(MouseHit(state.OptInteger(1, MOUSE_LEFT))>0)
		Return 1
	End
End

Class MojoFuncTouchX Extends MonkeyFunction
	Method Func:Int(state:LuaState)
		state.PushNumber(TouchX(state.OptInteger(1, 0)))
		Return 1
	End
End

Class MojoFuncTouchY Extends MonkeyFunction
	Method Func:Int(state:LuaState)
		state.PushNumber(TouchY(state.OptInteger(1, 0)))
		Return 1
	End
End

Class MojoFuncTouchDown Extends MonkeyFunction
	Method Func:Int(state:LuaState)
		state.PushBoolean(TouchDown(state.OptInteger(1, 0))>0)
		Return 1
	End
End

Class MojoFuncTouchHit Extends MonkeyFunction
	Method Func:Int(state:LuaState)
		state.PushBoolean(TouchHit(state.OptInteger(1, 0))>0)
		Return 1
	End
End

Class MojoFuncJoyX Extends MonkeyFunction
	Method Func:Int(state:LuaState)
		Local index:Int = state.OptInteger(1, 0)
		Local unit:Int = state.OptInteger(2, 0)
		state.PushNumber(JoyX(index, unit))
		Return 1
	End
End

Class MojoFuncJoyY Extends MonkeyFunction
	Method Func:Int(state:LuaState)
		Local index:Int = state.OptInteger(1, 0)
		Local unit:Int = state.OptInteger(2, 0)
		state.PushNumber(JoyY(index, unit))
		Return 1
	End
End

Class MojoFuncJoyZ Extends MonkeyFunction
	Method Func:Int(state:LuaState)
		Local index:Int = state.OptInteger(1, 0)
		Local unit:Int = state.OptInteger(2, 0)
		state.PushNumber(JoyZ(index, unit))
		Return 1
	End
End

Class MojoFuncJoyDown Extends MonkeyFunction
	Method Func:Int(state:LuaState)
		Local button:Int = state.ToInteger(1)
		Local unit:Int = state.OptInteger(2, 0)
		state.PushBoolean(JoyDown(button, unit)>0)
		Return 1
	End
End

Class MojoFuncJoyHit Extends MonkeyFunction
	Method Func:Int(state:LuaState)
		Local button:Int = state.ToInteger(1)
		Local unit:Int = state.OptInteger(2, 0)
		state.PushBoolean(JoyHit(button, unit)>0)
		Return 1
	End
End

Class MojoFuncAccelX Extends MonkeyFunction
	Method Func:Int(state:LuaState)
#If TARGET="glfw"
		state.PushNumber(0)
#Else
		state.PushNumber(AccelX())
#End
		Return 1
	End
End

Class MojoFuncAccelY Extends MonkeyFunction
	Method Func:Int(state:LuaState)
#If TARGET="glfw"
		state.PushNumber(0)
#Else
		state.PushNumber(AccelY())
#End
		Return 1
	End
End

Class MojoFuncAccelZ Extends MonkeyFunction
	Method Func:Int(state:LuaState)
#If TARGET="glfw"
		state.PushNumber(0)
#Else
		state.PushNumber(AccelZ())
#End
		Return 1
	End
End

Public

Function RegisterMojoLua:Void(state:LuaState)
	' mojo/app.monkey functions
	New MojoFuncAppTitle().Register(state, "AppTitle")
	New MojoFuncLoadState().Register(state, "LoadState")
	New MojoFuncLoadString().Register(state, "LoadString")
	New MojoFuncMillisecs().Register(state, "Millisecs")
	New MojoFuncSaveState().Register(state, "SaveState")
	New MojoFuncSetUpdateRate().Register(state, "SetUpdateRate")
	New MojoFuncUpdateRate().Register(state, "UpdateRate")
	
	' mojo/audio.monkey functions
	New MojoFuncChannelState().Register(state, "ChannelState")
	New MojoFuncLoadSound().Register(state, "LoadSound")
	New MojoFuncMusicState().Register(state, "MusicState")
	New MojoFuncPauseChannel().Register(state, "PauseChannel")
	New MojoFuncPauseMusic().Register(state, "PauseMusic")
	New MojoFuncPlayMusic().Register(state, "PlayMusic")
	New MojoFuncPlaySound().Register(state, "PlaySound")
	New MojoFuncResumeChannel().Register(state, "ResumeChannel")
	New MojoFuncResumeMusic().Register(state, "ResumeMusic")
	New MojoFuncSetAudioDevice().Register(state, "SetAudioDevice")
	New MojoFuncSetChannelPan().Register(state, "SetChannelPan")
	New MojoFuncSetChannelRate().Register(state, "SetChannelRate")
	New MojoFuncSetChannelVolume().Register(state, "SetChannelVolume")
	New MojoFuncSetMusicVolume().Register(state, "SetMusicVolume")
	New MojoFuncStopChannel().Register(state, "StopChannel")
	New MojoFuncStopMusic().Register(state, "StopMusic")
	
	' mojo/graphics.monkey functions
	New MojoFuncCls().Register(state, "Cls")
	New MojoFuncDeviceWidth().Register(state, "DeviceWidth")
	New MojoFuncDeviceHeight().Register(state, "DeviceHeight")
	New MojoFuncDrawCircle().Register(state, "DrawCircle")
	New MojoFuncDrawEllipse().Register(state, "DrawEllipse")
	New MojoFuncDrawImage().Register(state, "DrawImage")
	New MojoFuncDrawImageRect().Register(state, "DrawImageRect")
	New MojoFuncDrawLine().Register(state, "DrawLine")
	New MojoFuncDrawOval().Register(state, "DrawOval")
	New MojoFuncDrawPoint().Register(state, "DrawPoint")
	New MojoFuncDrawPoly().Register(state, "DrawPoly")
	New MojoFuncDrawRect().Register(state, "DrawRect")
	New MojoFuncDrawText().Register(state, "DrawText")
	New MojoFuncGetAlpha().Register(state, "GetAlpha")
	New MojoFuncGetBlend().Register(state, "GetBlend")
	New MojoFuncGetColor().Register(state, "GetColor")
	New MojoFuncGetFont().Register(state, "GetFont")
	New MojoFuncGetMatrix().Register(state, "GetMatrix")
	New MojoFuncGetScissor().Register(state, "GetScissor")
	New MojoFuncInvTransform().Register(state, "InvTransform")
	New MojoFuncLoadImage().Register(state, "LoadImage")
	New MojoFuncPopMatrix().Register(state, "PopMatrix")
	New MojoFuncPushMatrix().Register(state, "PushMatrix")
	New MojoFuncRotate().Register(state, "Rotate")
	New MojoFuncScale().Register(state, "Scale")
	New MojoFuncSetAlpha().Register(state, "SetAlpha")
	New MojoFuncSetBlend().Register(state, "SetBlend")
	New MojoFuncSetColor().Register(state, "SetColor")
	New MojoFuncSetFont().Register(state, "SetFont")
	New MojoFuncSetMatrix().Register(state, "SetMatrix")
	New MojoFuncSetScissor().Register(state, "SetScissor")
	New MojoFuncTextHeight().Register(state, "TextHeight")
	New MojoFuncTextWidth().Register(state, "TextWidth")
	New MojoFuncTransform().Register(state, "Transform")
	New MojoFuncTranslate().Register(state, "Translate")
	
	' mojo/input.monkey functions
	New MojoFuncAccelX().Register(state, "AccelX")
	New MojoFuncAccelY().Register(state, "AccelY")
	New MojoFuncAccelZ().Register(state, "AccelZ")
	New MojoFuncDisableKeyboard().Register(state, "DisableKeyboard")
	New MojoFuncEnableKeyboard().Register(state, "EnableKeyboard")
	New MojoFuncGetChar().Register(state, "GetChar")
	New MojoFuncJoyDown().Register(state, "JoyDown")
	New MojoFuncJoyHit().Register(state, "JoyHit")
	New MojoFuncJoyX().Register(state, "JoyX")
	New MojoFuncJoyY().Register(state, "JoyY")
	New MojoFuncJoyZ().Register(state, "JoyZ")
	New MojoFuncKeyDown().Register(state, "KeyDown")
	New MojoFuncKeyHit().Register(state, "KeyHit")
	New MojoFuncMouseDown().Register(state, "MouseDown")
	New MojoFuncMouseHit().Register(state, "MouseHit")
	New MojoFuncMouseX().Register(state, "MouseX")
	New MojoFuncMouseY().Register(state, "MouseY")
	New MojoFuncTouchDown().Register(state, "TouchDown")
	New MojoFuncTouchHit().Register(state, "TouchHit")
	New MojoFuncTouchX().Register(state, "TouchX")
	New MojoFuncTouchY().Register(state, "TouchY")
	
	' mojo/input.monkey constants
	RegisterGlobal(state, "CHAR_BACKSPACE", CHAR_BACKSPACE)
	RegisterGlobal(state, "CHAR_TAB", CHAR_TAB)
	RegisterGlobal(state, "CHAR_ENTER", CHAR_ENTER)
	RegisterGlobal(state, "CHAR_ESCAPE", CHAR_ESCAPE)
	RegisterGlobal(state, "CHAR_DELETE", CHAR_DELETE)
	RegisterGlobal(state, "CHAR_PAGEUP", CHAR_PAGEUP)
	RegisterGlobal(state, "CHAR_PAGEDOWN", CHAR_PAGEDOWN)
	RegisterGlobal(state, "CHAR_END", CHAR_END)
	RegisterGlobal(state, "CHAR_HOME", CHAR_HOME)
	RegisterGlobal(state, "CHAR_LEFT", CHAR_LEFT)
	RegisterGlobal(state, "CHAR_UP", CHAR_UP)
	RegisterGlobal(state, "CHAR_RIGHT", CHAR_RIGHT)
	RegisterGlobal(state, "CHAR_DOWN", CHAR_DOWN)
	RegisterGlobal(state, "CHAR_INSERT", CHAR_INSERT)
	RegisterGlobal(state, "MOUSE_LEFT", MOUSE_LEFT)
	RegisterGlobal(state, "MOUSE_RIGHT", MOUSE_RIGHT)
	RegisterGlobal(state, "MOUSE_MIDDLE", MOUSE_MIDDLE)
	RegisterGlobal(state, "JOY_A", JOY_A)
	RegisterGlobal(state, "JOY_B", JOY_B)
	RegisterGlobal(state, "JOY_X", JOY_X)
	RegisterGlobal(state, "JOY_Y", JOY_Y)
	RegisterGlobal(state, "JOY_LB", JOY_LB)
	RegisterGlobal(state, "JOY_RB", JOY_RB)
	RegisterGlobal(state, "JOY_BACK", JOY_BACK)
	RegisterGlobal(state, "JOY_START", JOY_START)
	RegisterGlobal(state, "JOY_LEFT", JOY_LEFT)
	RegisterGlobal(state, "JOY_UP", JOY_UP)
	RegisterGlobal(state, "JOY_RIGHT", JOY_RIGHT)
	RegisterGlobal(state, "JOY_DOWN", JOY_DOWN)
	RegisterGlobal(state, "KEY_LMB", KEY_LMB)
	RegisterGlobal(state, "KEY_RMB", KEY_RMB)
	RegisterGlobal(state, "KEY_MMB", KEY_MMB)
	RegisterGlobal(state, "KEY_BACKSPACE", KEY_BACKSPACE)
	RegisterGlobal(state, "KEY_TAB", KEY_TAB)
	RegisterGlobal(state, "KEY_ENTER", KEY_ENTER)
	RegisterGlobal(state, "KEY_SHIFT", KEY_SHIFT)
	RegisterGlobal(state, "KEY_CONTROL", KEY_CONTROL)
	RegisterGlobal(state, "KEY_ESCAPE", KEY_ESCAPE)
	RegisterGlobal(state, "KEY_SPACE", KEY_SPACE)
	RegisterGlobal(state, "KEY_PAGEUP", KEY_PAGEUP)
	RegisterGlobal(state, "KEY_PAGEDOWN", KEY_PAGEDOWN)
	RegisterGlobal(state, "KEY_END", KEY_END)
	RegisterGlobal(state, "KEY_HOME", KEY_HOME)
	RegisterGlobal(state, "KEY_LEFT", KEY_LEFT)
	RegisterGlobal(state, "KEY_UP", KEY_UP)
	RegisterGlobal(state, "KEY_RIGHT", KEY_RIGHT)
	RegisterGlobal(state, "KEY_DOWN", KEY_DOWN)
	RegisterGlobal(state, "KEY_INSERT", KEY_INSERT)
	RegisterGlobal(state, "KEY_DELETE", KEY_DELETE)
	RegisterGlobal(state, "KEY_0", KEY_0)
	RegisterGlobal(state, "KEY_1", KEY_1)
	RegisterGlobal(state, "KEY_2", KEY_2)
	RegisterGlobal(state, "KEY_3", KEY_3)
	RegisterGlobal(state, "KEY_4", KEY_4)
	RegisterGlobal(state, "KEY_5", KEY_5)
	RegisterGlobal(state, "KEY_6", KEY_6)
	RegisterGlobal(state, "KEY_7", KEY_7)
	RegisterGlobal(state, "KEY_8", KEY_8)
	RegisterGlobal(state, "KEY_9", KEY_9)

	For Local i:Int = 65 To 90
		RegisterGlobal(state, "KEY_"+String.FromChar(i), i)
	Next

	RegisterGlobal(state, "KEY_F1", KEY_F1)
	RegisterGlobal(state, "KEY_F2", KEY_F2)
	RegisterGlobal(state, "KEY_F3", KEY_F3)
	RegisterGlobal(state, "KEY_F4", KEY_F4)
	RegisterGlobal(state, "KEY_F5", KEY_F5)
	RegisterGlobal(state, "KEY_F6", KEY_F6)
	RegisterGlobal(state, "KEY_F7", KEY_F7)
	RegisterGlobal(state, "KEY_F8", KEY_F8)
	RegisterGlobal(state, "KEY_F9", KEY_F9)
	RegisterGlobal(state, "KEY_F10", KEY_F10)
	RegisterGlobal(state, "KEY_F11", KEY_F11)
	RegisterGlobal(state, "KEY_F12", KEY_F12)
	RegisterGlobal(state, "KEY_SEMICOLON", KEY_SEMICOLON)
	RegisterGlobal(state, "KEY_EQUALS", KEY_EQUALS)
	RegisterGlobal(state, "KEY_COMMA", KEY_COMMA)
	RegisterGlobal(state, "KEY_MINUS", KEY_MINUS)
	RegisterGlobal(state, "KEY_PERIOD", KEY_PERIOD)
	RegisterGlobal(state, "KEY_SLASH", KEY_SLASH)
	RegisterGlobal(state, "KEY_TILDE", KEY_TILDE)
	RegisterGlobal(state, "KEY_OPENBRACKET", KEY_OPENBRACKET)
	RegisterGlobal(state, "KEY_BACKSLASH", KEY_BACKSLASH)
	RegisterGlobal(state, "KEY_CLOSEBRACKET", KEY_CLOSEBRACKET)
	RegisterGlobal(state, "KEY_QUOTES", KEY_QUOTES)
	RegisterGlobal(state, "KEY_JOY0", KEY_JOY0)
	RegisterGlobal(state, "KEY_JOY1", KEY_JOY1_A)
	RegisterGlobal(state, "KEY_JOY2", KEY_JOY2_A)
	RegisterGlobal(state, "KEY_JOY3", KEY_JOY3_A)
	RegisterGlobal(state, "KEY_JOY0_A", KEY_JOY0_A)
	RegisterGlobal(state, "KEY_JOY0_B", KEY_JOY0_B)
	RegisterGlobal(state, "KEY_JOY0_X", KEY_JOY0_X)
	RegisterGlobal(state, "KEY_JOY0_Y", KEY_JOY0_Y)
	RegisterGlobal(state, "KEY_JOY0_LB", KEY_JOY0_LB)
	RegisterGlobal(state, "KEY_JOY0_RB", KEY_JOY0_RB)
	RegisterGlobal(state, "KEY_JOY0_BACK", KEY_JOY0_BACK)
	RegisterGlobal(state, "KEY_JOY0_START", KEY_JOY0_START)
	RegisterGlobal(state, "KEY_JOY0_LEFT", KEY_JOY0_LEFT)
	RegisterGlobal(state, "KEY_JOY0_UP", KEY_JOY0_UP)
	RegisterGlobal(state, "KEY_JOY0_RIGHT", KEY_JOY0_RIGHT)
	RegisterGlobal(state, "KEY_JOY0_DOWN", KEY_JOY0_DOWN)
	RegisterGlobal(state, "KEY_JOY1_A", KEY_JOY1_A)
	RegisterGlobal(state, "KEY_JOY1_B", KEY_JOY0_B+$20)
	RegisterGlobal(state, "KEY_JOY1_X", KEY_JOY0_X+$20)
	RegisterGlobal(state, "KEY_JOY1_Y", KEY_JOY0_Y+$20)
	RegisterGlobal(state, "KEY_JOY1_LB", KEY_JOY0_LB+$20)
	RegisterGlobal(state, "KEY_JOY1_RB", KEY_JOY0_RB+$20)
	RegisterGlobal(state, "KEY_JOY1_BACK", KEY_JOY0_BACK+$20)
	RegisterGlobal(state, "KEY_JOY1_START", KEY_JOY0_START+$20)
	RegisterGlobal(state, "KEY_JOY1_LEFT", KEY_JOY0_LEFT+$20)
	RegisterGlobal(state, "KEY_JOY1_UP", KEY_JOY0_UP+$20)
	RegisterGlobal(state, "KEY_JOY1_RIGHT", KEY_JOY0_RIGHT+$20)
	RegisterGlobal(state, "KEY_JOY1_DOWN", KEY_JOY0_DOWN+$20)
	RegisterGlobal(state, "KEY_JOY2_A", KEY_JOY2_A)
	RegisterGlobal(state, "KEY_JOY2_B", KEY_JOY0_B+$40)
	RegisterGlobal(state, "KEY_JOY2_X", KEY_JOY0_X+$40)
	RegisterGlobal(state, "KEY_JOY2_Y", KEY_JOY0_Y+$40)
	RegisterGlobal(state, "KEY_JOY2_LB", KEY_JOY0_LB+$40)
	RegisterGlobal(state, "KEY_JOY2_RB", KEY_JOY0_RB+$40)
	RegisterGlobal(state, "KEY_JOY2_BACK", KEY_JOY0_BACK+$40)
	RegisterGlobal(state, "KEY_JOY2_START", KEY_JOY0_START+$40)
	RegisterGlobal(state, "KEY_JOY2_LEFT", KEY_JOY0_LEFT+$40)
	RegisterGlobal(state, "KEY_JOY2_UP", KEY_JOY0_UP+$40)
	RegisterGlobal(state, "KEY_JOY2_RIGHT", KEY_JOY0_RIGHT+$40)
	RegisterGlobal(state, "KEY_JOY2_DOWN", KEY_JOY0_DOWN+$40)
	RegisterGlobal(state, "KEY_JOY3_A", KEY_JOY3_A)
	RegisterGlobal(state, "KEY_JOY3_B", KEY_JOY0_B+$60)
	RegisterGlobal(state, "KEY_JOY3_X", KEY_JOY0_X+$60)
	RegisterGlobal(state, "KEY_JOY3_Y", KEY_JOY0_Y+$60)
	RegisterGlobal(state, "KEY_JOY3_LB", KEY_JOY0_LB+$60)
	RegisterGlobal(state, "KEY_JOY3_RB", KEY_JOY0_RB+$60)
	RegisterGlobal(state, "KEY_JOY3_BACK", KEY_JOY0_BACK+$60)
	RegisterGlobal(state, "KEY_JOY3_START", KEY_JOY0_START+$60)
	RegisterGlobal(state, "KEY_JOY3_LEFT", KEY_JOY0_LEFT+$60)
	RegisterGlobal(state, "KEY_JOY3_UP", KEY_JOY0_UP+$60)
	RegisterGlobal(state, "KEY_JOY3_RIGHT", KEY_JOY0_RIGHT+$60)
	RegisterGlobal(state, "KEY_JOY3_DOWN", KEY_JOY0_DOWN+$60)
	
	For Local i:Int = 0 Until 32
		RegisterGlobal(state, "KEY_TOUCH"+i, KEY_TOUCH0+i)
	Next
End
